import { UserPlayer } from "../../scene/player/entity/UserPlayer";
import { RolePlayer } from "../../scene/player/entity/RolePlayer";
import { Cache } from "../../cache/Cache";
type int = number;
//class SearchPlayerData
    
    export  class SearchPlayerData
    {
        

        public static setAllPlayer(arg1: Array<any>): void
        {
            var loc1=null;
            SearchPlayerData.playerArr.length = 0;
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                loc1 = arg1[loc2] as UserPlayer;
                if (loc1) 
                {
                    if (loc1 is RolePlayer == false && SearchPlayerData.isDifferSex(loc1) && loc1.isDoubleRest == false && loc1.entityInfo.isStall == false && loc1.isTurned == false && loc1.isFlying == false && loc1.entityInfo.entityInfo.entityId.id > 0) 
                    {
                        SearchPlayerData.playerArr.push(loc1);
                    }
                }
                ++loc2;
            }
            var loc3=SearchPlayerData.playerArr.length;
            SearchPlayerData.setMaxPage(loc3);
            return;
        }

        /* internal  */static isDifferSex(arg1: UserPlayer): Boolean
        {
            var loc3=null;
            var loc1=arg1.sex;
            var loc2=false;
            if (SearchPlayerData.isZazenSame) 
            {
                loc2 = true;
            }
            else 
            {
                loc3 = Cache.instance.marry.playerMarry;
                if (!(loc1 == RolePlayer.instance.sex) || loc3 && arg1.entityInfo && arg1.entityInfo.entityInfo.name == loc3.mate.name) 
                {
                    loc2 = true;
                }
            }
            return loc2;
        }

        public static getCurPagePlayer(arg1: int): Array<any>
        {
            var loc5=null;
            var loc1=[];
            var loc2=(arg1 - 1) * SearchPlayerData.DataNum;
            var loc3=arg1 * SearchPlayerData.DataNum;
            var loc4=[];
            var loc6=0;
            while (loc6 < SearchPlayerData.playerArr.length) 
            {
                if ((loc5 = SearchPlayerData.playerArr[loc6] as UserPlayer).entityInfo.entityInfo.name != "") 
                {
                    loc4.push(loc5);
                }
                ++loc6;
            }
            loc1 = loc4.slice(loc2, loc3);
            SearchPlayerData.setMaxPage(loc4.length);
            return loc1;
        }

        public static getMaxPage(): int
        {
            return SearchPlayerData.curMaxPage;
        }

        public static searchPlayerByName(arg1: string): Array<any>
        {
            var loc2=null;
            var loc1=[];
            var loc3=0;
            while (loc3 < SearchPlayerData.playerArr.length) 
            {
                loc2 = SearchPlayerData.playerArr[loc3] as UserPlayer;
                if (loc2.entityInfo.entityInfo.name.search(arg1) != -1) 
                {
                    loc1.push(loc2);
                }
                ++loc3;
            }
            var loc4=loc1.length;
            SearchPlayerData.setMaxPage(loc4);
            return loc1;
        }

        /* internal  */static setMaxPage(arg1: int): void
        {
            var loc1=arg1 % SearchPlayerData.DataNum;
            if (loc1 == 0) 
            {
                SearchPlayerData.curMaxPage = arg1 / DataNum;
            }
            else 
            {
                SearchPlayerData.curMaxPage = arg1 / DataNum + 1;
            }
            return;
        }

        /* internal */ static /* const */DataNum: int=5;

        public static /* var */playerArr: Array<any>;

        /* internal */ static /* var */curMaxPage: int;

        public static /* var */isZazenSame: Boolean=false;
    }

            SearchPlayerData.playerArr = [];
            SearchPlayerData.isZazenSame = false;
        